package com.bipa.dao;

import com.bipa.bean.ShopCar;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ShopCarDao {

    //根据用户id以及商品id获取购物详情信息
    @Select("SELECT * FROM ec_shopcar  where user_id = #{userId} and article_id = #{articleId} ")
    public ShopCar getShopCarByUserIdAndArticleId(@Param("userId") int userId, @Param("articleId") int articleId);

    //更新购买数量
    @Update("update ec_shopcar set buynum = buynum + #{number} where  user_id = #{userId} and article_id = #{articleId}")
    public void updateShopcar(@Param("userId") int userId, @Param("articleId") int articleId, @Param("number") int number);

    //加入商品信息至购物车
    @Insert("insert into ec_shopcar(buynum,user_id,article_id)  values(#{number},#{userId},#{articleId})")
    public void addShopcar(@Param("userId") int userId, @Param("articleId") int articleId, @Param("number") int number);

    //根据用户id获取用户用户购物车中商品信息
    @Select("select * from ec_shopcar where user_id  = #{id}")
    public List<ShopCar> getShopCarByUserId(@Param("id") int id);

    @Update("update ec_shopcar set buynum = #{number} where  user_id = #{userId} and article_id = #{articleId}")
    public void updateShopcarTow(@Param("userId") int userId, @Param("articleId") int articleId, @Param("number") int number);

    @Delete("delete from  ec_shopcar  where user_id = #{userId} and article_id = #{articleId}")
    public void deleteShopCarById(@Param("userId") int userId, @Param("articleId") int articleId);
}
